<?php
class isp_customer_trial_model extends MY_Model {
	var $model = 'isp_customer_trial';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	
					a.kode_customer,
					b.nama as nama_customer,
					a.no_trial,
					a.status_customer,
					TO_CHAR(a.tanggal_invoice,'DD/MM/YYYY') a.tanggal_invoice,
					TO_CHAR(a.tanggal_bayar,'DD/MM/YYYY') a.tanggal_bayar,
					a.lama_trial,
					a.keterangan,
					a.biaya_pendaftaran,
					a.terbilang,
					a.total_bayar
					FROM	isp_customer_trial a
					LEFT JOIN isp_customer b on a.kode_customer = b.kode_customer
					WHERE lower(a.status_customer) = lower('Trial') AND (UPPER(a.no_trial) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(b.nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'a.no_trial' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
	
	function GetJSON2()
	{
		$ls_sql	= "	SELECT
					kode_customer,
					nama as nama_customer,
					status as status_customer,
					tgl_trial as lama_trial
					FROM	ISP_CUSTOMER					
					WHERE lower(status) = lower('Trial')
							and (UPPER(kode_customer) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'kode_customer' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));		
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert('isp_customer_trial', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('isp_customer_trial', $arr_data, $arr_rule);
		$this->db->update('isp_customer', array('status' => $arr_data['status_customer']));
	}
	
	function GetSingle($as_no_trial){
		$result = $this->db->get_where('isp_customer_trial', array('no_trial' => $as_no_trial));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_no_trial)
	{
		$result = $this->db->get_where('isp_customer_trial', array('no_trial' => $as_no_trial));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM isp_customer_trial WHERE no_trial = '".$arr_rule['no_trial']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['no_trial']."]<br />";
			}else{
				$this->db->delete('isp_customer_trial', array('no_trial' => $arr_rule['no_trial']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>